import { onUnmounted, reactive,toRefs } from 'vue';
import { clock } from '@/hooks';
function random (min,max){
	return parseInt(Math.random()*(max-min)+min);
}

export default function  () {
	let task = null;
	let data = reactive({
		userTotal : {
			userToday : random(2814454,3010012),
			userLastDay : random(100,150),
			userLastMonth : random(200,290),
			percent : 0,
		},
		ageDistribution : {
			agedis : random(32,33),
			list : [
				{
					dis : '0-20',
					conut : random(444736,544736)
				},
				{
					dis : '20-30',
					conut : random(144736,244736)
				},{
					dis : '30-40',
					conut : random(344736,444736)
				},{
					dis : '>50',
					conut : random(544736,644736)
				}
			]
		},
		deviceCount : {
			count : random(20000,30000),
			list : [
				{
					name : 'IOS',
					value : random(50000,80000)
				},
				{
					name : 'Android',
					value : random(60000,80000)
				},{
					name : 'H5',
					value : random(10000,90000)
				}
			]
		},
		totalGender : {
			male : random(20000,30000),
			female : random(20000,30000),
		},
		lineChart : {
			legendData : ['去年新增骑手','今年新增骑手'],
			axisData : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
			data : [
				[5, 100, 70, 120, 80, 15, 200, 300, 195, 150, 80, 103],
				[10, 50, 80, 4, 90, 50, 105, 160, 111, 54, 108, 50]
			]
		},
		barChart : {
			name : ['苹果', '香蕉', '栗子', '柿子', '牛奶', '龙虾', '牛肉'],
			data : [random(30,20), random(200,400), random(40,100), random(200,400), random(200,400), random(500,600), random(200,400)]
		},
		centerHeader : {
			success : random(10,50),
			failed : random(10,50),
			salesAmount : random(4343,56788),
			totalOrders : random(343,56788),
			payedUsers : random(5454,56788),
			newUsers : random(45454,56788),
		},
		order : {
			growth : random(23333,55555),
			growthRate : random(20,150),
			date : [clock().time.value],
			data : [random(1,800)]
		}
	});
	task = setInterval(()=>{
		data.userTotal.userToday= random(2814454,3010012);
		data.userTotal.userLastDay= random(100,150);
		data.userTotal.userLastMonth= random(200,290),
		data.userTotal.percent= random(40,100)+'%';
		data.ageDistribution.agedis= random(32,48);
		data.ageDistribution.list= [
			{
				dis : '0-20',
				conut : random(444736,544736)
			},
			{
				dis : '20-30',
				conut : random(144736,244736)
			},{
				dis : '30-40',
				conut : random(344736,444736)
			},{
				dis : '>50',
				conut : random(544736,644736)
			}
		];
		data.deviceCount.count = random(20000,30000);
		data.deviceCount.list =  [
			{
				name : 'IOS',
				value : random(444736,544736)
			},
			{
				name : 'Android',
				value : random(144736,244736)
			},{
				name : 'H5',
				value : random(344736,444736)
			}
		];	
		data.totalGender.male= random(20000,30000);
		data.totalGender.female= random(20000,30000);
		data.lineChart.legendData= ['去年新增骑手订单','今年新增骑手订单'];
		data.lineChart.data = [
			[random(10,50), 50, 80, 4, random(40,100), 50, 105, random(40,100), 111, 54, 108, 50],
			[random(10,50), random(40,100), 70, random(40,300), 80, 15, 200, random(40,300), 195, 150, 80, 103],
		];
		data.barChart.name = ['柿子', '牛奶', '龙虾', '牛肉','苹果', '香蕉', '栗子'];
		data.barChart.data = [random(30,20), random(200,400), random(40,100), random(200,400), random(200,400), random(500,600), random(200,400)];
		data.centerHeader.success = random(10,50);
		data.centerHeader.failed = random(10,50);
		data.centerHeader.salesAmount = random(4343,56788);
		data.centerHeader.totalOrders =  random(343,56788);
		data.centerHeader.payedUsers = random(5454,56788);
		data.centerHeader.newUsers = random(45454,56788);
		data.order.growth  = random(23333,55555);
		data.order.growthRate = random(20,150);
		data.order.date.push(clock().time.value);
		data.order.data.push(random(1,800));

	},3000);

	onUnmounted(()=>{
		clearInterval(task);
	});

	return {
		...toRefs(data)
	};
}